package com.nami.logic.utils;

import com.nami.basic.packet.message.Message;
import com.nami.store.api.request.conversation.ConverItem;

public class ConverUtil {

    public static final String TEMPLATE_CONVER_CACHE_KEY = "appkey:%s|user_id:%s|grp:%s";

    public static final String TEMPLATE_C2C_CONVER_CACHE_KEY = "appkey:%s|user_id:%s|recv_id:%s";

    public static String genLocalCacheConverKey(String appKey, Message message) {
        return genLocalCacheConverKey(appKey, message.getSenderId(), message.getReceiverId());
    }

    public static String genLocalCacheConverKey(ConverItem converItem) {
        return genLocalCacheConverKey(converItem.getAppKey(), converItem.getUserId(), converItem.getTargetId());
    }


    public static String genLocalCacheConverKey(String appKey, String senderId, String receiverId) {
        return String.format(TEMPLATE_CONVER_CACHE_KEY, appKey, senderId, receiverId);
    }

    public static String genPrivateConverKey(String appKey, Message message) {
        return genPrivateCacheConverKey(appKey, message.getSenderId(), message.getReceiverId());
    }

    public static String genPrivateConverKey(String appKey, String senderId, String recvId) {
        return genPrivateCacheConverKey(appKey,  senderId, recvId);
    }

    public static String genPrivateCacheConverKey(String appKey, String senderId, String receiverId) {
        return String.format(TEMPLATE_C2C_CONVER_CACHE_KEY, appKey, senderId, receiverId);
    }

}
